package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.search.AlbumInfoIndex;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;

    // /api/search/albumInfo/findRankingList/{category1Id}/{dimension} get
    @GetMapping("/albumInfo/findRankingList/{category1Id}/{dimension}")
    public Result<List<AlbumInfoIndex>> findRankingList(@PathVariable("category1Id") Long category1Id,@PathVariable("dimension") String dimension){
        List<AlbumInfoIndex> albumInfoIndexList = searchService.findRankingList(category1Id,dimension);
        return Result.ok(albumInfoIndexList);
    }



    /**
     * 为定时更新首页排行榜提供调用接口
     * @return
     */
    @Operation(summary = "为定时更新首页排行榜提供调用接口")
    @GetMapping("/albumInfo/updateLatelyAlbumRanking")
    public Result updateLatelyAlbumRanking(){
        searchService.updateLatelyAlbumRanking();
        return Result.ok();
    }


    // /api/search/albumInfo/completeSuggest/{keyword} get
    @GetMapping("/albumInfo/completeSuggest/{keyword}")
    public Result<List<String>> completeSuggest(@PathVariable("keyword") String keyword){
        List<String> s = searchService.completeSuggest(keyword);
        return Result.ok(s);
    }

    // /api/search/albumInfo/{albumId}
    @GetMapping("/albumInfo/{albumId}")
    public Result<Map<String,Object>> albumItem(@PathVariable("albumId") Long albumId){
        Map<String,Object> map = searchService.albumItem(albumId);
        return Result.ok(map);
    }


    /**
     * 仅用于测试-将指定已存在专辑上架保存到索引库
     *
     * @param albumId
     * @return
     */
    @Operation(summary = "仅用于测试-将指定已存在专辑上架保存到索引库")
    @GetMapping("/albumInfo/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId) {
        searchService.upperAlbum(albumId);
        return Result.ok();
    }
    /**
     * 下架专辑-删除文档
     * @param albumId
     * @return
     */
    @Operation(summary = "该接口仅用于测试-下架专辑-删除文档")
    @GetMapping("/albumInfo/lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable Long albumId){
        searchService.lowerAlbum(albumId);
        return Result.ok();
    }
    /**
     * 站内检索，支持关键字、分类、标签条件分页检索，结果高亮
     *
     * @param albumIndexQuery
     * @return
     */
    @Operation(summary = "站内检索，支持关键字、分类、标签条件分页检索，结果高亮")
    @PostMapping("/albumInfo")
    public Result<AlbumSearchResponseVo> search(@RequestBody AlbumIndexQuery albumIndexQuery) {
        AlbumSearchResponseVo vo = searchService.search(albumIndexQuery);
        return Result.ok(vo);
    }
    // /api/search/albumInfo/channel/{category1Id} get
    @GetMapping("/albumInfo/channel/{category1Id}")
    public Result<List<Map<String,Object>>> getTopCategory3HotAlbumList(@PathVariable("category1Id") Long category1Id){
        List<Map<String,Object>> list = searchService.getTopCategory3HotAlbumList(category1Id);
        return Result.ok(list);
    }

}

